using System;
using System.Collections.Generic;
using System.Text;

using UMEVOR.DTO;
using UMEVOR.DAL;

namespace UMEVOR.BLL
{
    public class BLLT_USUARIO
    {

        #region Métodos de Validação

        private bool validarIncluir(T_USUARIO obj)
        {
            return true;
        }
        private bool validarAlterar(T_USUARIO obj)
        {
            return true;
        }
        private bool validarExcluir(T_USUARIO obj)
        {
            return true;
        }
        #endregion

        #region Métodos DML

        public bool incluir(T_USUARIO obj)
        {
            try
            {
                if (validarIncluir(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.incluir(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool incluir(T_USUARIO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_USUARIO obj in objs)
                {
                    if (!validarIncluir(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.incluir(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool alterar(T_USUARIO obj)
        {
            try
            {
                if (validarAlterar(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.alterar(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool alterar(T_USUARIO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_USUARIO obj in objs)
                {
                    if (!validarAlterar(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.alterar(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool excluir(T_USUARIO obj)
        {
            try
            {
                if (validarExcluir(obj))
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.excluir(obj);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public bool excluir(T_USUARIO[] objs)
        {
            try
            {
                bool bValidos = true;
                foreach (T_USUARIO obj in objs)
                {
                    if (!validarExcluir(obj))
                    {
                        bValidos = false;
                        break;
                    }
                }
                if (bValidos)
                {
                    DALConnection.beginTransaction();
                    DALT_USUARIO dal = new DALT_USUARIO();
                    dal.excluir(objs);
                    DALConnection.commitTransaction();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public T_USUARIO obterPorPK(string login, int id_perf)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                T_USUARIO obj = dal.obterPorPK(login,id_perf);
                DALConnection.commitTransaction();
                return obj;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public List<T_USUARIO> listarTodos()
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                List<T_USUARIO> objs = dal.listarTodos();
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public List<VOT_USUARIO> consultar(string login, int codPerfil)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                List<VOT_USUARIO> objs = dal.consultar(login, codPerfil);
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public Boolean validarLogin(string login, string senha)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                Boolean objs = dal.validarLogin(login, senha);
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public String validarAcesso(string login, string pagina)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                string objs = dal.validarAcesso(login, pagina);
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }

        public Boolean validarMenu(string login, string sigla)
        {
            try
            {
                DALConnection.beginTransaction();
                DALT_USUARIO dal = new DALT_USUARIO();
                Boolean objs = dal.validarMenu(login, sigla);
                DALConnection.commitTransaction();
                return objs;
            }
            catch (Exception ex)
            {
                DALConnection.rollbackTransaction();
                throw ex;
            }
        }
        #endregion

    }
}
